// 编译命令 g++ ./cppWorkspace/temp.cpp -o ./cppWorkspace/a
// 运行命令 ./cppWorkspace/a

#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    int search(vector<int>& nums, int target) {
        int left = 0;
        int right = nums.size() - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (nums[mid] == target) {
                return mid;
            }
            else if (nums[mid] > target) {
                right = mid - 1;
            }
            else{
                left = mid + 1;
            }
        }
        return -1;
    }
    vector<int> inputVector() {
        int n;
        cout << "输入数字个数 n" << endl;
        cin >> n;
        vector<int> res;
        cout << "现在请输入数组元素" << endl;
        for (int i = 0; i < n; i++) {
            int t;
            cin >> t;
            res.push_back(t);
        }
        return res;
    }
};

int main() {
    Solution solution;
    vector<int> inputVector = solution.inputVector();
    int target;
    cout << "请输入 target" << endl;
    cin >> target;
    cout << solution.search(inputVector, target) << endl;
    return 0;
}